/*
 * Copyright (c) Jan Šlahora (${USER}) - 2011.
 * Created in IntelliJ IDEA 10.5
 */

/*
 * Created by JFormDesigner on Wed Nov 16 18:17:37 CET 2011
 */

package MW;

import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.FileReader;
import java.util.*;
import javax.net.ssl.SSLEngineResult;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.Document;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;

import GUIComponents.HlavniKomponentyComponents.HlKompGraf;
import GUIComponents.PravdepodobnostBar;
import GUIComponents.Tabulka;
import MW.CetnostiTaby.TabComponentsDemo;
import com.jgoodies.forms.factories.*;
import com.jgoodies.forms.layout.*;
import statistics.Asonance.AsonanceFixniPosun;
import statistics.Asonance.IAsonance;
import statistics.Pocitani;
import statistics.poznavaniTextu.MnozinaCharakteristik;
import statistics.poznavaniTextu.PointBasen;
import statistics.tests.*;
import GUIComponents.StatusBar2;


/**
 * @author Karel Novak
 */
public class MW extends JFrame {
  private MyDocumentListener myDocumentListener = new MyDocumentListener();
  private TabComponentsDemo tCD = new TabComponentsDemo();
  private JTabbedPane tabbedPane1 = tCD.getPane();
  private JEditorPane editorPane1 = dejEditorPane(null);
  private IAsonance asonceFixniPosun = new AsonanceFixniPosun();
  MnozinaCharakteristik mnozinaCharakteristik = new MnozinaCharakteristik();

  public MW() {
    try {
      // Set System L&F
      UIManager.setLookAndFeel(
          UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      System.err.println("Error when setting Look and Feel");
      JOptionPane.showMessageDialog(null, "Error when setting Look and Feel", "Error", JOptionPane.ERROR_MESSAGE);
    }
    //nastavTabbedPanel();


    initComponents();
    setEditorPane1(editorPane1);
    MWClasses.pridejLisenera(tabbedPane1);
    pridejEditorTab(editorPane1);
    vlozStatusBar(new StatusBar2(editorPane1.getText()));
    pnlForTabs.add(tCD.getPane(), CC.xy(1, 1));
    //nastavTabbedPanel();
  }


  private void pridejEditorTab(Component c) {
    String title = c.getName();
    JScrollPane jsp = new JScrollPane(c);
    //JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jsp, jsp);
    if (title!=null) {

      tCD.getPane().addTab(title, jsp);
    } else {
      tCD.getPane().addTab("Tab", jsp);
    }
    btn_open.setEnabled(true);
    tCD.runTest(tCD.getPane().getTabCount() - 1);
  }

  private void pridejTableTab(Component c) {
    String title = c.getName();
    JScrollPane jsp = new JScrollPane(c);
    if (title != null) {
      tCD.getPane().addTab(title, jsp);
    } else {
      tCD.getPane().addTab("Tab", jsp);
    }
    btn_open.setEnabled(true);
//    tCD.runTest();
    tCD.runTest(tCD.getPane().getTabCount() - 1);
  }

  private void pridejTableTab(Component c, Component c2, double lamda) {
    //... panel na vypočet rozdělení
    PravdepodobnostBar pravdepodobnostBar = new PravdepodobnostBar();

    String title = c.getName();

    //... scroll panely
    JScrollPane jsp = new JScrollPane(c);
    JScrollPane jsp2 = new JScrollPane(c2);

    //... rozdělovací panel
    JSplitPane splitPane = new JSplitPane();

    splitPane.setLeftComponent(jsp);
    splitPane.setRightComponent(jsp2);


    //... panel na vložení
    JPanel obal = new JPanel(new BorderLayout());
    
    obal.add(splitPane);

    obal.add(pravdepodobnostBar, BorderLayout.SOUTH);

    if (title != null) {
      //tCD.getPane().addTab(title, splitPane);
      tCD.getPane().addTab(title, obal);
    } else {
      //tCD.getPane().addTab("Tab", splitPane);
      tCD.getPane().addTab("Tab", obal);
    }
    btn_open.setEnabled(true);
//    tCD.runTest();
    tCD.runTest(tCD.getPane().getTabCount() - 1);
    try
    {
      double chi = Pocitani.chiKvadrat(dejSloupecTabulky((JTable) c, 1), dejSloupecTabulky((JTable) c2, 0));

      int k = dejSloupecTabulky((JTable) c, 0).length;
      double chiKH = new Pocitani().getChiKritickaHodnota(k-2, 0.95);
      pravdepodobnostBar.setValues(lamda, chi, chiKH);
    } catch (Exception ex) {
      ex.printStackTrace();

    }
    splitPane.setDividerLocation( tCD.getPane().getComponent(0).getWidth() / 2);
  }

  public void pridejPanelTab(Component c) {
    String title = c.getName();
    if (title != null) {
      tCD.getPane().addTab(title, c);
    } else {
      tCD.getPane().addTab("Tab", c);
    }
    btn_open.setEnabled(true);

    tCD.runTest(tCD.getPane().getTabCount() - 1);
  }

  public IAsonance getAsonceFixniPosun() {
    return asonceFixniPosun;
  }

  private void mI_openActionPerformed(ActionEvent e) {
    MWClasses.otevritSoubor(this);
  }

  private void mI_exitActionPerformed(ActionEvent e) {
    MWClasses.konec(0, this);
  }

  public void setText(File f) {
    try {
      FileReader fr = new FileReader(f);
      editorPane1.read(fr, null);
      editorPane1.setName(MWClasses.dejJmeno(f.getName()));
      tCD.prejmenujTab(MWClasses.dejJmeno(f.getName()));

      vlozStatusBar(new StatusBar2(editorPane1.getText()));

      //new StatusBar(pnl_status_bar, editorPane1.getText());
      btn_analyse.setEnabled(true);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  public void setTexty(File[] files) {
    if (tabbedPane1.getTabCount() == 0) {
      this.btnNewTabActionPerformed(null);
    }

    if (editorPane1.getText().length() == 0) {
      int index = tCD.getPane().getSelectedIndex();
      tCD.odstranTab(index);
      tCD.runTest();
    }

    for (int i = 0; i < files.length; i++) {
      try {
        FileReader fr = new FileReader(files[i]);
        pridejEditorTab((files[i].getName()));
        editorPane1.read(fr, null);
        
        btn_analyse.setEnabled(true);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    tCD.runTest();
  }

  Component dejAktPanel() {
    return tabbedPane1;
  }



  private void button1ActionPerformed(ActionEvent e) {
    MWClasses.otevritSoubor(this);

  }

  private void thisComponentResized(ComponentEvent e) {
    //.. kvůli scrollbarům
    if (editorPane1.getParent()!=null) {
      editorPane1.setSize(editorPane1.getParent().getSize());
    }
    editorPane1.repaint();
  }


  private void thisWindowClosing(WindowEvent e) {
    MWClasses.konec(0, this);
  }

  public JEditorPane getEditorPane1() {
    return this.editorPane1;
  }
  
  protected void editorPane1CaretUpdate(CaretEvent e) {
  
  }

  private void btn_analyseActionPerformed(ActionEvent e) {
    //editorPane1.setEnabled(false);
    if (tabbedPane1.getTabCount()>0)
    {
      Component c = tabbedPane1.getSelectedComponent();
      if (MWClasses.getJEditorPaneOnActualTab(c) != null)
      {
        setEditorPane1(MWClasses.getJEditorPaneOnActualTab(c));
        WindowCetnosti wc = new WindowCetnosti(this);
        wc.setVisible(true);

        //.. je-li v asonanci víc než jeden text, je možné ho otestovat Bartelettem
        if (asonceFixniPosun.getaTest().getMereni().size() > 0) {
          setMenuAsonanceFixniPosun(true);
          if (asonceFixniPosun.getaTest().getMereni().size() > 1) {
            setButtonAsonanceFixniTest(true);
          }
        }

      } else {
        JOptionPane.showMessageDialog(this, "Zvoleny tab neobsahuje text");
      }
    }
  }

  private void setButtonAsonanceFixniTest(boolean add) {

    if (add) {
      toolBar1.add(btnAsonanceFixniPosun);
      menuAsonanceFixniPosun.add(menuItemAsonanceFixniPosun, 0);
    }
  }

  private void setMenuAsonanceFixniPosun(boolean add) {
    if (add) {
      if (menuAsonanceFixniPosun != null) {
        menuBar1.remove(menuAsonanceFixniPosun);
      }
      
      menuAsonanceFixniPosun = new JMenu("Asonance");

      menuAsonanceFixniPosun.addSeparator();

      if (this.asonceFixniPosun.getaTest().getMereni().size() > 0) {
        for(ATest.Mereni mereni : this.asonceFixniPosun.getaTest().getMereni()) {
          String jmeno = mereni.getJmeno();

          JMenu autorMenu = new JMenu(jmeno);

          final JMenuItem smazat = new JMenuItem("Smazat");
          smazat.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              smazatZAsonance(e, smazat);
            }
          });
          autorMenu.add(smazat);
          menuAsonanceFixniPosun.add(autorMenu);
        }
        menuBar1.add(menuAsonanceFixniPosun);
        menuBar1.revalidate();
      }
      else {
        menuBar1.remove(menuAsonanceFixniPosun);
        menuAsonanceFixniPosun = null;
        menuBar1.repaint();
      }
    }
  }

  private void smazatZAsonance(ActionEvent e, JMenuItem smazat) {
    String autor = ((JMenu) ((JPopupMenu) smazat.getParent()).getInvoker()).getText();

    if(((AsonanceFixniPosun) asonceFixniPosun).remove(autor)) {
      setMenuAsonanceFixniPosun(true);
    }
  }

  private void pnl_status_barMouseReleased(MouseEvent e) {

  }

  private void btn_analyseMouseReleased(MouseEvent e) {

  }

  public void addPanel(String title, String[] hlavicka, Object o) {
    addPanel(title, hlavicka, o, false);
  }
  public void addPanel(String title, String[] hlavicka, Object o, boolean sort) {
    if (o instanceof HashMap) {
      //.. priprava JTable
      JTable t = new Tabulka(hlavicka, ((HashMap) o), sort).getTable();

      Tabulka tabulka = new Tabulka(t);
      JTable t2 = tabulka.getTable();
      t.setName(title);

      if (t2 == null) {
        pridejTableTab(t);
      } else {
        pridejTableTab(t, t2, tabulka.getP().getLambda());
      }
    } else if (o instanceof JTable) {
      ((JTable) o).setName(title);
      pridejTableTab((JTable) o);
    } else if (o instanceof JPanel) {
      ((JPanel) o).setName(title);
      pridejPanelTab(((JPanel) o));
    }
  }

  public String dejText() {
    return editorPane1.getText();
  }

  public ArrayList<String> dejTexty() {
    return tCD.dejTexty(tCD.getPane().getTabCount());
  }

  public HashMap<String, String> dejTextyHM() {
    return tCD.dejTextyHM(tCD.getPane().getTabCount());
  }

  public void setLabelVelVyberu(String s) {
    labelVelikostVyberu.setText(s);
  }


  private void btnNewTabActionPerformed(ActionEvent e) {
    pridejEditorTab(dejEditorPane(null));
    selectLast();
  }

  private void pridejEditorTab(String title) {
    pridejEditorTab(dejEditorPane(title));
    selectLast();
  }

  private JEditorPane dejEditorPane(String title) {
    JEditorPane p = new JEditorPane();
    p.getDocument().addDocumentListener(myDocumentListener);
    String jmeno = MWClasses.dejJmeno(title);
    if (jmeno == null) {
      jmeno = "Text " + (tCD.getPane().getTabCount()+1);
    }
    p.setName(jmeno);
    return p;
  }
  private void selectLast() {
    int posledni = tabbedPane1.getTabCount() - 1;
    tabbedPane1.setSelectedIndex(posledni);
    Component c = tabbedPane1.getSelectedComponent();
    setEditorPane1(MWClasses.getJEditorPaneOnActualTab(c));
    setBtnAnalyseViditelnost();
  }

  public void setBtnAnalyseViditelnost() {
    Component c = tabbedPane1.getSelectedComponent();
  // setEditorPane1(MWClasses.getJEditorPaneOnActualTab(c));
    if (editorPane1 == null || editorPane1.getText() == null || editorPane1.getText().length() == 0) {
      btn_analyse.setEnabled(false);
    }
  }

  private Object[] dejSloupecTabulky(JTable t, int sloupec) {
    ArrayList<Object> al = new ArrayList<>();
    for(int i = 0; i < t.getRowCount(); i++) {
      al.add((t.getModel().getValueAt(i, sloupec)));
    }
    return al.toArray();
  }
  public JButton getBtn_open() {
    return btn_open;
  }

  public void setEditorPane1(JEditorPane editorPane1) {
    if (editorPane1 != null) {
      if (this.editorPane1 == editorPane1) {
        return;
      }
      this.editorPane1 = editorPane1;
      this.editorPane1.getDocument().addDocumentListener(myDocumentListener);
      vlozStatusBar(new StatusBar2(editorPane1.getText()));
    }
  }

  private void btn_openFolderActionPerformed(ActionEvent e) {
    MWClasses.otevritSlozku(this);
  }

  private void buttonZavritVseActionPerformed(ActionEvent e) {
    tCD.odstranTaby();
    btnNewTabActionPerformed(null);
  }

  private void buttonMnozinaActionPerformed(ActionEvent e) {
    if (mnozinaCharakteristik == null) {
      mnozinaCharakteristik = new MnozinaCharakteristik();
    }
    
    String autor = (String) JOptionPane.showInputDialog(this, "Zadejte jméno autora:", "Jméno autora", JOptionPane.QUESTION_MESSAGE, null, null, "");

    HashMap<String, String> texty = dejTextyHM();
    if (texty.size() > 0) {
      mnozinaCharakteristik.add(texty, autor);
    }
  }

  private void buttonHKGrafActionPerformed(ActionEvent e) {
    HashMap<String, ArrayList<PointBasen>> hm = mnozinaCharakteristik.getAutoriBody();
    double sumaVsechLambda = mnozinaCharakteristik.getSumaVsechLambda();
    double sumaDvouLambda = mnozinaCharakteristik.getSumaDvouLambda();
    this.addPanel("Graf", null, new HlKompGraf(hm, sumaDvouLambda, sumaVsechLambda), false);
  }

  private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner Evaluation license - Karel Novak
    ResourceBundle bundle = ResourceBundle.getBundle("cs");
    menuBar1 = new JMenuBar();
    menu_File = new JMenu();
    mI_open = new JMenuItem();
    mItemOpenFolder = new JMenuItem();
    mI_exit = new JMenuItem();
    menu1 = new JMenu();
    menuItem1 = new JMenuItem();
    menuItem2 = new JMenuItem();
    toolBar1 = new JToolBar();
    btnNewTab = new JButton();
    buttonZavritVse = new JButton();
    btn_open = new JButton();
    btn_openFolder = new JButton();
    btn_analyse = new JButton();
    buttonMnozina = new JButton();
    buttonHKGraf = new JButton();
    pnlForTabs = new JPanel();
    pnl_status_bar = new JPanel();
    panelStatusBar = new JPanel();
    panel1 = new JPanel();
    labelVelikostVyberu = new JLabel();

    //======== this ========
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setLocationByPlatform(true);
    setTitle(bundle.getString("MW.this.title"));
    addComponentListener(new ComponentAdapter() {
      @Override
      public void componentResized(ComponentEvent e) {
        thisComponentResized(e);
        thisComponentResized(e);
      }
    });
    addWindowListener(new WindowAdapter() {
      @Override
      public void windowClosing(WindowEvent e) {
        thisWindowClosing(e);
      }
    });
    Container contentPane = getContentPane();
    contentPane.setLayout(new FormLayout(
      "22dlu:grow",
      "default, $lgap, 24dlu:grow, $lgap, 17dlu"));

    //======== menuBar1 ========
    {

      //======== menu_File ========
      {
        menu_File.setText(bundle.getString("MW.menu_File.text"));

        //---- mI_open ----
        mI_open.setText(bundle.getString("MW.mI_open.text"));
        mI_open.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            mI_openActionPerformed(e);
          }
        });
        menu_File.add(mI_open);

        //---- mItemOpenFolder ----
        mItemOpenFolder.setText(bundle.getString("MW.mItemOpenFolder.text"));
        mItemOpenFolder.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            btn_openFolderActionPerformed(e);
          }
        });
        menu_File.add(mItemOpenFolder);
        menu_File.addSeparator();

        //---- mI_exit ----
        mI_exit.setText(bundle.getString("MW.mI_exit.text"));
        mI_exit.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            mI_exitActionPerformed(e);
          }
        });
        menu_File.add(mI_exit);
      }
      menuBar1.add(menu_File);

      //======== menu1 ========
      {
        menu1.setText(bundle.getString("MW.menu1.text"));

        //---- menuItem1 ----
        menuItem1.setText(bundle.getString("MW.menuItem1.text"));
        menuItem1.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            btn_analyseActionPerformed(e);
          }
        });
        menu1.add(menuItem1);

        //---- menuItem2 ----
        menuItem2.setText(bundle.getString("MW.menuItem2.text"));
        menuItem2.setEnabled(false);
        menu1.add(menuItem2);
      }
      menuBar1.add(menu1);
    }
    setJMenuBar(menuBar1);

    //======== toolBar1 ========
    {
      toolBar1.setFloatable(false);

      //---- btnNewTab ----
      btnNewTab.setText(bundle.getString("MW.btnNewTab.text"));
      btnNewTab.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
          btnNewTabActionPerformed(e);
        }
      });
      toolBar1.add(btnNewTab);

      //---- buttonZavritVse ----
      buttonZavritVse.setText(bundle.getString("MW.buttonZavritVse.text"));
      buttonZavritVse.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
          buttonZavritVseActionPerformed(e);
        }
      });
      toolBar1.add(buttonZavritVse);
      toolBar1.addSeparator();

      //---- btn_open ----
      btn_open.setText(bundle.getString("MW.btn_open.text"));
      btn_open.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
          button1ActionPerformed(e);
        }
      });
      toolBar1.add(btn_open);

      //---- btn_openFolder ----
      btn_openFolder.setText(bundle.getString("MW.btn_openFolder.text"));
      btn_openFolder.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
          btn_openFolderActionPerformed(e);
        }
      });
      toolBar1.add(btn_openFolder);
      toolBar1.addSeparator();

      //---- btn_analyse ----
      btn_analyse.setText(bundle.getString("MW.btn_analyse.text"));
      btn_analyse.setEnabled(false);
      btn_analyse.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
          btn_analyseActionPerformed(e);
        }
      });
      btn_analyse.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
          btn_analyseMouseReleased(e);
        }
      });
      toolBar1.add(btn_analyse);

      //---- buttonMnozina ----
      buttonMnozina.setText(bundle.getString("MW.buttonMnozina.text"));
      buttonMnozina.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
          buttonMnozinaActionPerformed(e);
        }
      });
      toolBar1.add(buttonMnozina);

      //---- buttonHKGraf ----
      buttonHKGraf.setText(bundle.getString("MW.buttonHKGraf.text"));
      buttonHKGraf.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
          buttonHKGrafActionPerformed(e);
        }
      });
      toolBar1.add(buttonHKGraf);
    }
    contentPane.add(toolBar1, CC.xy(1, 1));

    //======== pnlForTabs ========
    {

      // JFormDesigner evaluation mark
      /*pnlForTabs.setBorder(new javax.swing.border.CompoundBorder(
          new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
               "JFormDesigner Evaluation", javax.swing.border.TitledBorder.CENTER,
               javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 12),
               java.awt.Color.red), pnlForTabs.getBorder()));*/

      pnlForTabs.addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});

           pnlForTabs.setLayout(new BoxLayout(pnlForTabs, BoxLayout.X_AXIS));
         }
         contentPane.add(pnlForTabs, CC.xywh(1, 2, 1, 2) );

         //======== pnl_status_bar ========
         {
           pnl_status_bar.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
           pnl_status_bar.addMouseListener(new MouseAdapter() {
             @Override
             public void mouseReleased(MouseEvent e) {
               pnl_status_barMouseReleased(e);
             }
           });
           pnl_status_bar.setLayout(new FormLayout(
             "81dlu:grow, $lcgap, 107dlu",
             "default"));

           //======== panelStatusBar ========
           {
             panelStatusBar.setLayout(new FormLayout(
               "default:grow",
               "fill:default:grow"));
           }
           pnl_status_bar.add(panelStatusBar, CC.xy(1, 1));

           //======== panel1 ========
           {
             panel1.setLayout(new FormLayout(
               "default:grow",
               "default"));

             //---- labelVelikostVyberu ----
             labelVelikostVyberu.setHorizontalAlignment(SwingConstants.RIGHT);
             labelVelikostVyberu.setHorizontalTextPosition(SwingConstants.RIGHT);
             panel1.add(labelVelikostVyberu, CC.xy(1, 1));
           }
           pnl_status_bar.add(panel1, CC.xy(3, 1));
         }
         contentPane.add(pnl_status_bar, CC.xy(1, 5));
         setSize(945, 640);
         setLocationRelativeTo(getOwner());
         // JFormDesigner - End of component initialization  //GEN-END:initComponents

         btnAsonanceFixniPosun = new JButton("Analyzovat asonanci");
         btnAsonanceFixniPosun.addActionListener(new ActionListener() {
           @Override
           public void actionPerformed(ActionEvent e) {
             asonanceFixniPosunActionPerformed(e);
           }
         });
         menuItemAsonanceFixniPosun = new JMenuItem("Analyzovat asonanci");
         menuItemAsonanceFixniPosun.addActionListener(new ActionListener() {
           @Override
           public void actionPerformed(ActionEvent e) {
             asonanceFixniPosunActionPerformed(e);
           }
         });
       }

       private void asonanceFixniPosunActionPerformed(ActionEvent e) {
         String nazev = ("Analýza rozptylu asonance - posun o " + ((AsonanceFixniPosun) asonceFixniPosun).getPosun());
         String ret = "<h1>" + nazev + "</h1>";
         try {
           ret += "<h2>Bartlettův test</h2>";
           //..bartlet -> anova X Kruskal-Wallis
           Bartlett b = new Bartlett(asonceFixniPosun);
           ret += "<table><tr><td>";
           ret += "B = </td><td>" + b.getB() + "</td></tr>";
           double chi = new Pocitani().getChiKritickaHodnota(asonceFixniPosun.getaTest().getK()-1, 0.95);
           ret += "<tr><td>&chi;<sub>k-1</sub>(&alpha;) = &chi;<sub>" + asonceFixniPosun.getaTest().getN() + " -1</sub>(&alpha;) = </td><td>" + chi + "</td></tr></table>";
           boolean HA;
           ITest test;
           if (b.getB() < chi) {
             ret += "<br><br><b>Nulová hypotéza není zamítnuta</b>";
             ret += "<h2>Anova</h2>";
             test = new Anova(asonceFixniPosun);

             //..test HA
             double F = (new Pocitani().getFKritickaHodnota(test.getKvel() - 1, (test.getNvel() - test.getKvel()), 0.95));
             HA = (test.getTestovaStatistika() >= F);
           } else {
             ret += "<br><br><b>Nulová hypotéza je zamítnuta</b>";
             ret += "<h2>Kruskall-Wallisův test</h2>";

             test = new KruskallWallis(asonceFixniPosun);
             //..test HA
             HA = (test.getTestovaStatistika() >= new Pocitani().getChiKritickaHodnota(test.getKvel() - 1, 0.95));
           }
           ret += test.toString();
           if (HA) { //..posun o sedm
             ret += "<h2>Schéffeho metoda</h2>";
             Scheffe scheffe = new Scheffe(test, asonceFixniPosun);
             ret += scheffe.vypis();
           }


         } catch (Exception ex) {
           ex.printStackTrace();
         }
         JEditorPane vystup = new JEditorPane();

         vystup.setEditable(false);

         HTMLEditorKit kit = new HTMLEditorKit();

         StyleSheet css = kit.getStyleSheet();
         css.addRule("body {font-family: Tahoma,Geneva,Kalimati,sans-serif;}");
         css.addRule("table {border-spacing: 8px;}");
         css.addRule("td {padding: 1px  20px;}");

         vystup.setEditorKit(kit);

         Document doc = kit.createDefaultDocument();
         vystup.setDocument(doc);
         vystup.setText(ret);
         JScrollPane jsp = new JScrollPane(vystup);
         jsp.setName(nazev);
         pridejPanelTab(jsp);
       }
       // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
       // Generated using JFžžžormDesigner Evaluation license - Karel Novak
       private JMenuBar menuBar1;
       private JMenu menu_File;
       private JMenuItem mI_open;
       private JMenuItem mItemOpenFolder;
       private JMenuItem mI_exit;
       private JMenu menu1;
       private JMenuItem menuItem1;
       private JMenuItem menuItem2;
       private JToolBar toolBar1;
       private JButton btnNewTab;
       private JButton buttonZavritVse;
       private JButton btn_open;
       private JButton btn_openFolder;
       private JButton btn_analyse;
       private JButton buttonMnozina;
       private JButton buttonHKGraf;
       private JPanel pnlForTabs;
       private JPanel pnl_status_bar;
       private JPanel panelStatusBar;
       private JPanel panel1;
       private JLabel labelVelikostVyberu;
       // JFormDesigner - End of variables declaration  //GEN-END:variables
       private JButton btnAsonanceFixniPosun;
       private JMenu menuAsonanceFixniPosun;
       private JMenuItem menuItemAsonanceFixniPosun;

       public TabComponentsDemo gettCD() {
         return tCD;
       }

       class MyDocumentListener implements DocumentListener {

         /**
          * Gives notification that there was an insert into the document.  The
          * range given by the DocumentEvent bounds the freshly inserted region.
          *
          * @param e the document event
          */
    @Override
    public void insertUpdate(DocumentEvent e) {
      updateSB();
    }

    /**
     * Gives notification that a portion of the document has been
     * removed.  The range is given in terms of what the view last
     * saw (that is, before updating sticky positions).
     *
     * @param e the document event
     */
    @Override
    public void removeUpdate(DocumentEvent e) {
      updateSB();
    }

    /**
     * Gives notification that an attribute or set of attributes changed.
     *
     * @param e the document event
     */
    @Override
    public void changedUpdate(DocumentEvent e) {
      //To change body of implemented methods use File | Settings | File Templates.
    }

    private void updateSB() {
      String stary = ((StatusBar2) panelStatusBar.getComponent(0)).getText();
      if (stary != null) {
        if (editorPane1.getText().equals(stary)) {
          return;
        }
      }

      vlozStatusBar(new StatusBar2(editorPane1.getText()));

      if (editorPane1.getText().length()!=0) {
        btn_analyse.setEnabled(true);
      } else {
        btn_analyse.setEnabled(false);
      }
    }


    //StatusBar2.statusBar(pnl_status_bar, editorPane1.getText());
  }

  private void vlozStatusBar(StatusBar2 sb) {
    sb.run();
    panelStatusBar.removeAll();
    panelStatusBar.add(sb, CC.xy(1, 1));
    panelStatusBar.validate();
  }
}
